/*
 * @Author: yangrongxin
 * @Date: 2021-08-04 14:15:54
 * @LastEditors: liubin
 * @LastEditTime: 2021-10-12 18:57:05
 */
import { View, Text, Image, Button } from '@tarojs/components';
import Taro from '@tarojs/taro';
import { SIZE_TYPE } from './dataDictionary';
import styles from './index.module.less';

const EvaluationItem = (props: {
  headImg: string; // 封面图片
  measureTableId: string; // 量表id
  name: string; // 量表名称
  price: string; // 量表价格 price为0.00的时候对应免费
  // 扩展配置字段
  size?: SIZE_TYPE;
  extendWapperClass?: string; // 覆盖wapper的样式
  enableStatus?: number; //是否上架
}) => {
  const {
    headImg = 'https://hxgywx.oss-cn-shenzhen.aliyuncs.com/nursing-customer/assets/articleVideoCover.png',
    name = '测试数据',
    price = '0.00',
    size = SIZE_TYPE.NORMAL,
    measureTableId,
    extendWapperClass,
    enableStatus
  } = props;
  const toDetail = () => {
    if (enableStatus === 2) return;
    Taro.navigateTo({
      url: `/pages/AssessmentDetail/index?measureTableId=${measureTableId}`,
    });
  };
  return (
    <View
      className={`${styles.evalutaionItem} ${size === SIZE_TYPE.NORMAL ? '' : styles.evalutaionItemSmall
        } ${extendWapperClass}`}
      onClick={() => toDetail()}
    >
      {/* 展示背景图片区域 */}
      <Image
        src={headImg}
        mode="aspectFill"
        className={size === SIZE_TYPE.NORMAL ? styles.imageNormal : styles.imageSmall}
      />
      {/* 展示购买描述区域 */}
      <View className={size === SIZE_TYPE.NORMAL ? styles.flexContent : styles.wrapContent}>
        <Text className="ellipsisText">{`${name}`}</Text>
        <Button>{price === '0.00' ? '免费' : `¥${price}`}</Button>
        {enableStatus === 2 && <Button type="primary">已停用</Button>}
      </View>
    </View>
  );
};

export default EvaluationItem;
